package com.crm.CLdriving.controller;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import com.crm.CLdriving.dto.req.RegisterReqDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.crm.CLdriving.common.BaseResponse;
import com.crm.CLdriving.dto.req.LoginReqDto;
import com.crm.CLdriving.dto.resp.LoginRespDto;
import com.crm.CLdriving.service.LoginService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;

import java.util.HashMap;

@Controller
@RequestMapping("login")
@Api(tags="登录")
@Log4j2
public class LoginController {
	
	@Autowired
	private LoginService loginService;
	
	
	@ApiOperation("登录接口")
	@PostMapping("select")
	@ResponseBody
    public BaseResponse<LoginRespDto> adminLogin( @RequestBody @Valid LoginReqDto loginReqDto,  HttpServletRequest request) {
		log.info("请求数据："+JSON.toJSONString(loginReqDto));		  
		return loginService.login(loginReqDto);
	}

	@ApiOperation("用户登录接口")
	@PostMapping("")
	@ResponseBody
	public BaseResponse<LoginRespDto> userLogin( @RequestBody @Valid LoginReqDto loginReqDto,  HttpServletRequest request) {
		log.info("请求数据："+JSON.toJSONString(loginReqDto));
		return loginService.login(loginReqDto);
	}

	@ApiOperation("用户注册接口")
	@PostMapping("/register")
	@ResponseBody
	public BaseResponse<?> register(@RequestBody @Valid RegisterReqDto registerReqDto,HttpServletRequest request){
		log.info("请求数据："+JSON.toJSONString(registerReqDto));
		return loginService.register(registerReqDto);
	}


}
